import { GlobalEvent } from "../base/GlobalEvent";

const {ccclass, property} = cc._decorator;

@ccclass
export default class rangeTips extends cc.Component {

    private pos:cc.Vec2 = null;
    private scaleX:number = null;
    private scaleY:number = null;


    onLoad () {
        GlobalEvent.on(GlobalEvent.Event.swtichAttackMode, this.swtichAttackMode.bind(this),this);

        this.pos = this.node.position;
        this.scaleX = this.node.scaleX;
        this.scaleY = this.node.scaleY;
    }

    swtichAttackMode(Event){
        if(Event){
            this.node.cleanup();
            this.node.active = true;
            this.node.scaleX += 0.5*this.node.scaleX;
            this.node.scaleY += 0.5*this.node.scaleY;
            var tween = new cc.Tween();
            tween.target(this.node)
                .to(0.25, {scaleX: this.scaleX, scaleY:this.scaleY, opacity:150}, null)
                .start();
        }
        else{
            this.node.cleanup();
            this.node.active = true;
            this.node.scaleX = this.scaleX;
            this.node.scaleY = this.scaleY;
            var tween = new cc.Tween();
            tween.target(this.node)
                .to(0.25, {scaleX: 1.5*this.node.scaleX, scaleY: 1.5*this.node.scaleY, opacity:0}, null)
                .call(function(){
                    this.node.active = false;
                }.bind(this))
                .start();
        }
    }
}
